package com.diamond.web.model.system;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.validator.constraints.NotBlank;
import com.diamond.core.util.ValidMessage;
@Entity
@Table(name="sys_role")
@JsonIgnoreProperties({"permissions"})
public class Role {
	@Id
	@GeneratedValue
    private Long id;

	@NotBlank(message=ValidMessage.ROLE_NAME_NULL)
	@Column(nullable=false)
    private String roleName;

    @NotBlank(message=ValidMessage.ROLE_SIGN_NULL)
    @Column(unique=true,nullable=false)
    private String roleSign;

    private String description;
    
    @ManyToMany
    @JoinTable(name="sys_role_permission")
    private Set<Permission> permissions;

    public Role(){
    	
    }
    
    public Role(Long rid) {
	}

	public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName == null ? null : roleName.trim();
    }

    public String getRoleSign() {
        return roleSign;
    }

    public void setRoleSign(String roleSign) {
        this.roleSign = roleSign == null ? null : roleSign.trim();
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description == null ? null : description.trim();
    }

	public Set<Permission> getPermissions() {
		return permissions;
	}

	public void setPermissions(Set<Permission> permissions) {
		this.permissions = permissions;
	}
	
	@Override
	public String toString() {
		return "Role:"+roleName+"  Sign:"+roleSign;
	}
}